import { ACCESS_TOKEN } from '@/store/mutation-types'
import request from '@/utils/request'
import storage from 'store'

/**
 * 获取订单详情
 * @param {*} params
 * @returns
 */
export function findOrder(params) {
    return request({
        url: '/api/order/find',
        method: 'get',
        params
    })
}

/**
 * 分页获取订单
 * @param {*} params {
 *  page 页码
 *  limit 页数
 * }
 */
export function findOrderList(params) {
    return request({
        url: '/api/order/findList',
        method: 'get',
        params
    })
}

/**
 * 删除订单
 * @param {*} params {
 *  id 管理员Id
 * }
 * @returns
 */
export function delOrder(params) {
    return request({
        url: '/api/order/del',
        method: 'delete',
        params: { id: params.id }
    })
}

/**
 * 标记订单
 * @param {*} data
 * @returns
 */
export function orderTag(data) {
    return request({
        url: '/api/order/orderTag',
        method: 'post',
        data
    })
}

/**
 * 一键配送订单
 * @param {*} data
 * @returns
 */
export function deliveryOrder(data) {
    return request({
        url: '/api/order/deliveryOrder',
        method: 'post',
        data
    })
}

/**
 * 订单加急
 * @param {*} data
 * @returns
 */
export function urgetnOrder(data) {
    return request({
        url: '/api/order/urgetnOrder',
        method: 'post',
        data
    })
}

/**
 * 订单同步
 * @param {*} data
 * @returns
 */
export function syncOrder(data) {
    return request({
        url: '/api/order/syncOrder',
        method: 'post',
        data
    })
}

/**
 * 解密订单数据
 * @param {*} params
 * @returns
 */
export function decryptionOrder(params) {
    return request({
        url: '/api/order/decryptionOrder',
        method: 'post',
        data: { id: params.id }
    })
}

/**
 * 修改订单
 * @param {*} data
 * @returns
 */
export function editOrder(data) {
    return request({
        url: '/api/order/editOrder',
        method: 'post',
        data
    })
}

/**
 * 订单导出
 * @param {*} params
 */
export function exportOrder(params) {
    const token = storage.get(ACCESS_TOKEN)

    window.open(`${process.env.VUE_APP_API_BASE_URL}/api/order/exportOrder?${params}&token=${token}`)
}

/**
 * 获取订单商品
 * @param {*} params
 * @returns
 */
export function findOrderGoodsList(params) {
    return request({
        url: '/api/orderGoods/findList',
        method: 'get',
        params
    })
}

/**
 * 订单商品导出
 * @param {*} params
 */
export function exportOrderGoods(params) {
    const token = storage.get(ACCESS_TOKEN)

    window.open(`${process.env.VUE_APP_API_BASE_URL}/api/orderGoods/exportOrderGoods?${params}&token=${token}`)
}

/**
 * 修改订单商品
 * @param {*} data
 * @returns
 */
export function editOrderGoods(data) {
    return request({
        url: '/api/orderGoods/edit',
        method: 'post',
        data
    })
}

/**
 * 获取订单修改日志
 * @param {*} params
 * @returns
 */
export function findOrderLogList(params) {
    return request({
        url: '/api/orderLog/findList',
        method: 'get',
        params
    })
}

/**
 * 阅读日志
 * @param {*} data
 * @returns
 */
export function readOrderLog(data) {
    return request({
        url: '/api/orderLog/read',
        method: 'post',
        data
    })
}

/**
 * 统计未读的订单修改日志
 * @param {*} params
 * @returns
 */
export function countOrderLog(params) {
    return request({
        url: '/api/orderLog/count',
        method: 'get',
        params
    })
}

/**
 * 获取订单统计
 * @param {*} params
 * @returns
 */
export function findOrderCountList(params) {
    return request({
        url: '/api/order/orderCount',
        method: 'get',
        params
    })
}

/**
 * 订单商品导出
 * @param {*} params
 */
export function exportOrderCount(params) {
    const token = storage.get(ACCESS_TOKEN)
    window.open(`${process.env.VUE_APP_API_BASE_URL}/api/order/exportOrderCount?${params}&token=${token}`)
}
